package com.wxq.maliao;

import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

public class BackGround {
    // 背景图片
    private BufferedImage bgImage = null;
    // 当前场景
    private int sort;
    // 是否最后一个场景
    private boolean flag;

    private List<Obstacle> obstacleList = new ArrayList<>();

    private BufferedImage gan = null;

    // 用于存放我们所有的敌人
    private List<Enemy> enemieList = new ArrayList<>();

    private BufferedImage tower = null;

    // 是否到达旗杆位置
    private boolean isReach = false;

    // 判断旗子是否落地
    private boolean isBase = false;

    public BackGround() {

    }

    public BackGround(int sort, boolean flag) {
        this.sort = sort;
        this.flag = flag;
        if (flag) {
            bgImage = StaticValue.bg2;
        } else {
            bgImage = StaticValue.bg;
        }

        if (1 == sort) {
            // 挥着第一关的地面，上地面type= 1，下地面type= 2
            for (int i = 0; i < 27; i++) {
                obstacleList.add(new Obstacle(i * 30, 420, 1, this));
            }

            for (int i = 0; i <= 120; i += 30) {
                for (int j = 0; j < 27; j++) {
                    obstacleList.add(new Obstacle(j * 30, 570 - i, 2, this));
                }
            }


            // 绘制砖块A
            for (int i = 120; i <= 150; i += 30) {
                obstacleList.add(new Obstacle(i, 300, 7, this));
            }

            // 绘制砖块B-F
            for (int i = 300; i <= 570; i += 30) {
                if (i == 360 || i == 390 || i == 480 || i == 510 || i == 540) {
                    obstacleList.add(new Obstacle(i, 300, 7, this));
                } else {
                    obstacleList.add(new Obstacle(i, 300, 0, this));
                }
            }
            // j
            for (int i = 420; i <= 450; i += 30) {
                obstacleList.add(new Obstacle(i, 200, 7, this));
            }
            // 绘制水管
            for (int i = 360; i <= 600; i += 25) {
                if (360 == i) {
                    obstacleList.add(new Obstacle(620, i, 3, this));
                    obstacleList.add(new Obstacle(645, i, 4, this));
                } else {
                    obstacleList.add(new Obstacle(620, i, 5, this));
                    obstacleList.add(new Obstacle(645, i, 6, this));
                }
            }
            // 绘制第一关蘑菇敌人
            enemieList.add(new Enemy(580,385, 1,true,this ));
            // 绘制食人花敌人
            enemieList.add(new Enemy(635,420,2,328,428,true,this));
        }

        // 判断是否是第二关
        if (sort == 2) {
            // 挥着第一关的地面，上地面type= 1，下地面type= 2
            for (int i = 0; i < 27; i++) {
                obstacleList.add(new Obstacle(i * 30, 420, 1, this));
            }

            for (int i = 0; i <= 120; i += 30) {
                for (int j = 0; j < 27; j++) {
                    obstacleList.add(new Obstacle(j * 30, 570 - i, 2, this));
                }
            }

            // 绘制水管

            // 绘制水管
            for (int i = 360; i <= 600; i += 25) {
                if (360 == i) {
                    obstacleList.add(new Obstacle(60, i, 3, this));
                    obstacleList.add(new Obstacle(85, i, 4, this));
                } else {
                    obstacleList.add(new Obstacle(60, i, 5, this));
                    obstacleList.add(new Obstacle(85, i, 6, this));
                }
            }

            // 绘制水管2
            for (int i = 330; i <= 600; i += 25) {
                if (330 == i) {
                    obstacleList.add(new Obstacle(620, i, 3, this));
                    obstacleList.add(new Obstacle(645, i, 4, this));
                } else {
                    obstacleList.add(new Obstacle(620, i, 5, this));
                    obstacleList.add(new Obstacle(645, i, 6, this));
                }
            }

            // 绘制砖块c
            obstacleList.add(new Obstacle(300, 330, 0, this));

            // 绘制砖块BEG
            for (int i = 270; i <= 330; i += 30) {
                if (i == 270 || i == 330) {
                    obstacleList.add(new Obstacle(i, 360, 0, this));
                } else {
                    obstacleList.add(new Obstacle(i, 360, 7, this));
                }
            }

            // 绘制砖块ADFHI
            for (int i = 240; i <= 360; i += 30) {
                if (i == 240 || i == 360) {
                    obstacleList.add(new Obstacle(i, 390, 0, this));
                } else {
                    obstacleList.add(new Obstacle(i, 390, 7, this));
                }
            }
            // 绘制妨碍1砖块
            obstacleList.add(new Obstacle(240, 300, 0, this));

            // 绘制空1-4砖块
            for (int i = 360; i <= 540; i += 60) {
                obstacleList.add(new Obstacle(i, 270, 7, this));

            }

            // 绘制第一关蘑菇敌人1
            enemieList.add(new Enemy(200,385, 1,true,this ));
            // 绘制第一关蘑菇敌人1
            enemieList.add(new Enemy(500,385, 1,true,this ));
            // 绘制食人花敌人1
            enemieList.add(new Enemy(75,420,2,328,418,true,this));
            // 绘制食人花敌人2
            enemieList.add(new Enemy(635,420,2,298,388,true,this));
        }
        // 绘制场景3
        if (3 == sort) {
            // 挥着第一关的地面，上地面type= 1，下地面type= 2
            for (int i = 0; i < 27; i++) {
                obstacleList.add(new Obstacle(i * 30, 420, 1, this));
            }

            for (int i = 0; i <= 120; i += 30) {
                for (int j = 0; j < 27; j++) {
                    obstacleList.add(new Obstacle(j * 30, 570 - i, 2, this));
                }
            }
            // 绘制A-O砖块
            int temp = 290;
            for (int i = 390; i >= 270; i -= 30) {
                for (int j = temp; j <= 410; j += 30) {
                    obstacleList.add(new Obstacle(j, i, 7, this));
                }
                temp += 30;
            }

            // 绘制第三个有背景的砖块
            temp = 60;
            for (int i = 390; i >= 360; i -= 30) {
                for (int j = temp; j <= 90; j += 30) {
                    obstacleList.add(new Obstacle(j, i, 7, this));
                }
                temp += 30;
            }
            // 绘制第一关蘑菇敌人1
            enemieList.add(new Enemy(150,385, 1,true,this ));

            gan = StaticValue.gan;

            tower = StaticValue.tower;

            obstacleList.add(new Obstacle(515, 220, 8, this));


        }

    }

    public List<Obstacle> getObstacleList() {
        return obstacleList;
    }

    public BufferedImage getBgImage() {
        return bgImage;
    }

    public int getSort() {
        return sort;
    }

    public boolean isFlag() {
        return flag;
    }

    public BufferedImage getGan() {
        return gan;
    }

    public BufferedImage getTower() {
        return tower;
    }

    public boolean isReach() {
        return isReach;
    }

    public void setReach(boolean reach) {
        isReach = reach;
    }

    public boolean isBase() {
        return isBase;
    }

    public void setBase(boolean base) {
        isBase = base;
    }

    public List<Enemy> getEnemieList() {
        return enemieList;
    }
}
